package com.asp.controller;

import com.asp.context.BaseContext;
import com.asp.entity.User;
import com.asp.model.MyResults;
import com.asp.model.ResultDetial;
import com.asp.result.Result;
import com.asp.service.ResultsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Api(tags = "错题模块接口")
@RestController
@RequestMapping("/user/result")
@CrossOrigin
public class ResultsController {
    @Resource
    private ResultsService resultsService;


    //获取做题列表
    @ApiOperation(value = "做题列表")
    @GetMapping("/display")
    public Result<List<MyResults>> selectAllResults(){
        List<MyResults> allResults = resultsService.selectAllResults();
        return Result.success(allResults);
    }

    //错题详情
    @ApiOperation(value = "错题详情")
    @RequestMapping("/outcome")
    @ResponseBody
    public Result<ResultDetial> FalseContent(Integer testNum) {
        ResultDetial resultDetial = resultsService.selectTestByNum(testNum);
        return Result.success(resultDetial);
    }

    //提交回答并判断
    @ApiOperation(value = "提交回答并判断")
    @PostMapping("/judge")
    public Result<String> judgeTest(Integer testId,String userAnswer,String userName){
        String testAnswer = resultsService.judgeTest(testId,userAnswer,userName);
        return Result.success(testAnswer);
    }

    //提示关键词
    @ApiOperation(value = "提示关键词")
    @GetMapping("/tips")
    public Result<List<String>> getTips(Integer id){
        List<String> tips= resultsService.getTips(id);
        return Result.success(tips);
    }

    //删除作答
    @ApiOperation(value="删除作答")
    @DeleteMapping("/delete")
    public Result deleteResults(Integer testNum){
        resultsService.deleteResultsByNum(testNum);
        return Result.success();
    }

    //删除所有作答
    @DeleteMapping("/deleteAll")
    public Result deleteResults(){
        resultsService.deleteAllResults();
        return Result.success();
    }
}